package com.response; /**
 * @author wzm
 * @create 2023-03-06 16:17
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/resp03")
public class ResponseServlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //当访问Servelt方法时给浏览器响应字符串数据


        //响应数据之前设置数据的格式  以及数据 的编码
//        response.setCharacterEncoding("utf-8");//设置服务器字符集
//        response.setHeader("content-type","text/html;charset=utf-8");//浏览器要接受的文件格式 编码


        //同时设置服务器和客户端都是utf-8(推荐)
        response.setContentType("text/html;charset=utf-8");

        //字符输出流
        PrintWriter writer = response.getWriter();



        writer.write("aaa");
        writer.write("bbb");
        writer.write("ddd");
        writer.write("ddd");
        //模拟响应一个html  直接输出 标签识别为文字  中文乱码
        writer.write("<h1 style='color:red;'>你好</h1>");
        writer.write("<h1 style='color:red;'>你好</h1>");
        writer.write("<h1 style='color:red;'>你好</h1>");
        writer.write("<h1 style='color:red;'>你好</h1>");
        /*注意：使用Servlet向浏览写一个html极其复杂 后面我们学jsp来响应网页*/

    }
}
